<?php 
require_once 'BaseMySQLDAO.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../Entity/Domain/OptionsDomain.php';
class OptionsDAO extends BaseMySQLDAO
{
	public function __construct($context) {
		parent::__construct($context, OptionsDomain::$CollectionName);
	}

	public function create($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "INSERT INTO options(option_key,option_value,option_group,option_type,choices,help_text,processors,option_order,created_datetime,modified_datetime)
					VALUES	(
								'".$obj->getOption_key()."',
								".$obj->getOption_value().",
								'".$obj->getOption_group()."',
								'".$obj->getOption_type()."',
								".$obj->getChoices().",
								".$obj->getHelp_text().",
								".$obj->getProcessors().",
								".$obj->getOption_order().",
								'".$obj->getCreated_datetime()."',
								'".$obj->getModified_datetime()."'
							)";
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function deleteByOid($oid){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "DELETE FROM options WHERE option_key=".$oid;
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function update($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "UPDATE options
				SET
					options.option_value = ".$obj->getOption_value().",
					options.option_group = '".$obj->getOption_group()."',
					options.option_type = '".$obj->getOption_type()."',
					options.choices = ".$obj->getChoices().",
					options.help_text = ".$obj->getHelp_text().",
					options.processors = ".$obj->getProcessors().",
					options.option_order = ".$obj->getOption_order().",
					options.created_datetime = '".$obj->getCreated_datetime()."',
					options.modified_datetime = '".$obj->getModified_datetime()."'
				 WHERE option_key=".$obj->getOption_key();
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function findByOid($oid)
	{
		$optionsDomain = null;
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM options WHERE options.option_key = ".$oid;
		$res = $this->getMySQLConnection()->mysqlOneRow($inSQL);
		if($res)
		{
			$optionsDomain = new OptionsDomain($res);
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $optionsDomain;
	}

	public function findAll()
	{
		$optionsDomainArr = array();
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM options";
		$res = $this->getMySQLConnection()->mysqlData($inSQL);
		if($res)
		{
			while ($data = mysql_fetch_assoc($res))
			{
				$optionsDomain = new OptionsDomain($data);
				$optionsDomainArr[] = $optionsDomain;
			}
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $optionsDomain;
	}

}
?>